﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;

using FRL.DebtChased.Repository;
using FRL.DebtChased.Repository.PartModels;

namespace FRL.DebtChased.Website.FinanceParts
{

	/// <summary>
	/// Declaration of FinHitListTable class
	/// </summary>
	public class FinHitListTable : BaseWebPart
	{

		/////////////////////////////////////////////////////////////
		// Construction

		public FinHitListTable()
			:base("Hit List")
		{

		}

		/////////////////////////////////////////////////////////////
		// Implementation

		protected override int ContentWidth
		{
			get { return 340; }
		}

		protected override int ContentHeight
		{
			get { return 120; }
		}

		protected override string GrivViewSkinId
		{
			get { return "HitListGridView"; }
		}

		protected override void _fillContent(System.Web.UI.HtmlTextWriter w, Panel pnlScrool, GridView gridView)
		{

			// Add to html
			pnlScrool.RenderControl(w);

		}

		protected override void _loadModel()
		{

			// Get the current user id
			MySession mySession = MySession.BindMySession();
			int iUserId = mySession.UserID;
			if ((mySession.Roles & Definitions.eRoles.FIN_SYSADMIN) == Definitions.eRoles.FIN_SYSADMIN)
				iUserId = 0;

			// Get repository
			DebtChasedEntities ent = base._getEnt();

			// Load the model
			m_model = new HitListModel( ent, iUserId );

		}

		protected override void _bindGrid(GridView gridView)
		{

			// Shortcuts
			if (gridView.DataSource != null)
				return;
			if (m_model == null)
				return;

			// Set up grid
			gridView.DataSource = (m_model as HitListModel).Elements;
			gridView.DataBind();

		}

		protected override void _setFooterCells(GridViewRow row)
		{

			// Set totals
			row.Cells[3].Text = "Total:";
			row.Cells[4].Text = (m_model as HitListModel).m_mnTotal.ToString();

		}

		protected override void _processCommand(string strCommandName, int iId)
		{

			// Open the chaser for this account
			MySession mySession = MySession.BindMySession();
			mySession.SetHandover("DebtChaser.aspx", iId);
			HttpContext.Current.Response.Redirect("~/Finance/DebtChaser.aspx");

		}

	}

}